<template>
  <div class="search-container">
    <van-cell title="搜索历史">
      <template>
        <div v-if="isDel" class="right">
          <span @click="$emit('deleteAll')">全部删除</span>
          <span  @click="isDel = false">完成</span>
        </div>
        <van-icon @click="isDel = true" v-else name="delete-o"/>
      </template>
    </van-cell>
    <van-cell  @click="deleteItem(index)" v-for="(item,index) in history" :key="item" :title="item">
      <template #right-icon>
        <van-icon v-if="isDel" name="close"/>
      </template>
    </van-cell>
  </div>
</template>

<script>
export default {
  props: {
    history: {
      type: Array,
      require: true
    }
  },
  data () {
    return {
      isDel: false

    }
  },

  created () {

  },

  methods: {
    deleteItem (index) {
      if (this.isDel) {
        this.history.splice(index, 1)
      } else {
        this.$emit('search', this.history[index])
      }
    }
  }
}
</script>

<style lang="less" scoped>
.search-container{
  .right{
    span:nth-child(1){
      margin-right: 8px;
    }
  }
}
</style>
